<circuit access="internal">

	<fuseaction name="getArticles">
		<include template="qryGetArticles" />
	</fuseaction>
	
	<fuseaction name="loadArticle">
		<if condition="attributes.id is 'new'">
			<true>
				<do action="mArticle.blankArticle" />
			</true>
			<false>
				<do action="mArticle.getArticleById" />
				<do action="mArticle.loadArticle" />
			</false>
		</if>
		<do action="getCategories" />
		<if condition="lsIsDate(attributes.posted)">
			<true>
				<do action="convertdate" />
			</true>
		</if>
	</fuseaction>
	
	<fuseaction name="saveOrDeleteArticle">
		<if condition="structKeyExists(attributes,'delete')">
			<true>
				<do action="mArticle.deleteArticle" />
				<set name="hasErrors" value="false" />
			</true>
			<false>
				<do action="validateAndSaveArticle" />
			</false>
		</if>
	</fuseaction>
	
	<fuseaction name="validateAndSaveArticle">
		<do action="mArticle.validateArticle" />
		<if condition="len(errorStr)">
			<true>
				<!-- restore body, since it loses more body -->
				<set name="attributes.body" value="#origbody#"/>
				<set name="hasErrors" value="true" />
			</true>
			<false>
				<do action="mArticle.saveArticle" />
				<set name="hasErrors" value="false" />
			</false>
		</if>
	</fuseaction>

	<fuseaction name="saveNewComment">
		<do action="mArticle.getArticleById" />
		<do action="mComment.saveRememberedUser" />
		<do action="mComment.validateComment" />
		<if condition="not len(errorStr)">
			<true>
				<do action="mComment.addComment" />
				<do action="mComment.sendCommentNotification" />
			</true>
		</if>
		<do action="mComment.getCommentsByArticleId" />
		<do action="mComment.getBlankComment" />
	</fuseaction>
	
	<fuseaction name="loadComments">
		<do action="mArticle.getArticleById" />
		<do action="mComment.getCommentsByArticleId" />
		<do action="mComment.getBlankComment" />
		<do action="mComment.getRememberedUser" />
	</fuseaction>
		
	<fuseaction name="deleteComment">
		<do action="mComment.deleteComment" />
	</fuseaction>
	
	<fuseaction name="convertDate">
		<include template="actConvertDate" />
	</fuseaction>
	
	<fuseaction name="getCategories">
		<invoke object="application.blog" methodcall="getCategories()"
		 		returnvariable="allCats" />
	</fuseaction>
	
	<fuseaction name="login">
		<include template="actLogin" />
	</fuseaction>
	
	<fuseaction name="logout">
		<include template="actLogout" />
	</fuseaction>
	
	<fuseaction name="setup">
		<if condition="not structKeyExists(application,'init')">
			<true>
				<do action="m.initialize" />
			</true>
		</if>
	</fuseaction>
	
	<fuseaction name="initialize">
		<instantiate object="application.blog" class="blog" arguments="blogname" />
		<instantiate object="application.resourceBundle" class="resourceBundle"
			arguments="expandPath('./includes/main'), application.blog.getProperty('locale')" />
		<instantiate object="application.localeutils" class="localeUtilities"
			arguments="application.blog.getProperty('locale')" />
		<set name="application.root" value="blog" />
		<set name="application.init" value="true" />
	</fuseaction>
	
</circuit>